//角色管理模块的接口
import request from "../../../utils/request";
import type {RoleResponseData,RoleData, MenuResponseData} from '@/api/acl/role/type';
//枚举地址 
enum API{
    //获取全部的职位接口
    ALLROLE_URL='/admin/acl/role/',
    //新增岗位的接口地址
    ADDROLE_URL='/admin/acl/role/save',
    //更新已有的职位
    UPDATEROLE_URL='/admin/acl/role/update',
    //删除已有的职位
    DELETEROLE_URL='/admin/acl/role/remove/',
    //获取全部的菜单与按钮的数据
    ALLPERMISSION_URL='/admin/acl/permission/toAssign/',
    //给相应的职位分配权限
    SETPERMISSION_URL='/admin/acl/permission/doAssign/?',


}
//获取全部的职位接口
export const reqAllRoleList = (page:number,limit:number,roleName:string)=>request.get<any,RoleResponseData>(API.ALLROLE_URL+`${page}/${limit}/?roleName=${roleName}`)
//新增或修改已有的职位
export const reqAddOrUpdateRole=(data:RoleData)=>{
    if(data.id){
        return request.put<any,any>(API.UPDATEROLE_URL,data)
    }else{
        return request.post<any,any>(API.ADDROLE_URL,data)
    }
}
//删除某个已有的职位
export const reqDeleteRole=(id:number)=>request.delete(API.DELETEROLE_URL+id)
//获取全部的菜单与按钮的数据
export const reqAllMenuList=(roleId:number)=>request.get<any,MenuResponseData>(API.ALLPERMISSION_URL+roleId)
//给相应的职位下发权限
export const reqSetPermission =(roleId:number,permissionId:number[])=>request.post(API.SETPERMISSION_URL+`roleId=${roleId}&permissionId=${permissionId}`)